import QtQuick 2.0
import QtQuick.Window 2.0
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.0
import QtQml.Models 2.15
import Qt.labs.platform 1.1
import QtGraphicalEffects 1.15
import "qrc:/CustomComponent"
import SvgImage 1.0

Rectangle {
    id: root
    implicitWidth: 360
    implicitHeight: 96
    radius: 8
    color: "transparent"
    function show() { visible = true; opacity = 1; closeTimer.stop(); closeTimer.start() }
    function close() { opacity = 0 }
    Behavior on opacity{ NumberAnimation { duration: 500 } }
    onOpacityChanged: { if(opacity == 0) { visible = false }}

    function initDialog(filePath) {
        filePathText.text = filePath
    }

    Timer {
        id: closeTimer
        interval: 10000
        repeat: false
        running: false
        onTriggered: {
            close()
        }
    }

    DropShadow {
        anchors.fill: parent
        radius: 8.0
        samples: 12
        color: Theme.back_shadow_color
        source: back
    }

    Rectangle {
        id: back
        anchors.fill: parent
        radius: parent.radius
    }

    Rectangle {
        id: closeBtn
        implicitWidth: 34
        implicitHeight: 34
        anchors.right: parent.right
        anchors.top: parent.top
        color: "transparent"

        readonly property url source_normal: "qrc:/image_res/assets/image_res/prompt_close_34x34_normal.svg"
        readonly property url source_hover: "qrc:/image_res/assets/image_res/prompt_close_34x34_hover.svg"
        readonly property url source_pressed: "qrc:/image_res/assets/image_res/prompt_close_34x34_pressed.svg"

        SvgImage {
            id: btnImage
            source: closeBtn.source_normal
            smooth: true
            anchors.fill: parent
        }

        MouseArea {
            anchors.fill: parent
            hoverEnabled: true
            onClicked: { close() }
            onPressed: btnImage.source = closeBtn.source_pressed
            onReleased: btnImage.source = closeBtn.source_normal
            onEntered: btnImage.source = closeBtn.source_hover
            onExited: btnImage.source = closeBtn.source_normal
        }
    }

    ColumnLayout {
        anchors.fill: parent
        anchors.topMargin: 10
        anchors.leftMargin: 10
        anchors.rightMargin: 10
        anchors.bottomMargin: 14
        spacing: 0

        RowLayout {
            Layout.fillWidth: true

            Rectangle {
                implicitWidth: 16
                implicitHeight: width

                SvgImage {
                    source: "qrc:/image_res/assets/image_res/success.svg"
                    anchors.fill: parent
                }
            }
            CusText {
                text: TransText.promptDialog_File_Saved
                color: Theme.text_color
                font.pixelSize: Theme.font_size_14

                font.styleName: Theme.font_family_regular
            }
            CusText {
                text: TransText.promptDialog_Open_Folder
                color: "#3986FF"
                font.pixelSize: Theme.font_size_14

                font.styleName: Theme.font_family_regular
                font.underline: true

                MouseArea {
                    anchors.fill: parent
                    hoverEnabled: true

                    onEntered: {
                        cursorShape = Qt.PointingHandCursor
                    }
                    onExited: {
                        cursorShape = Qt.ArrowCursor
                    }

                    onClicked: {
                        console.log("open folder: " + filePathText.text)
                        quickTool.openFileInExplorer(filePathText.text)
                    }
                }
            }
        }

        Item { Layout.fillHeight: true }

        CusText {
            text: TransText.promptDialog_File_Saved_To
            color: Theme.text_color
            font.pixelSize: Theme.font_size_14

            font.styleName: Theme.font_family_regular
            Layout.topMargin: 10
        }

        CusText {
            id: filePathText
            text: "C:\\User\\xxx.xxx"
            color: Theme.text_color
            font.pixelSize: Theme.font_size_13

            font.styleName: Theme.font_family_regular
            Layout.fillWidth: true
            Layout.topMargin: 5
            elide: Text.ElideRight
        }
    }
}
